package com.example.moreconnected;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.clj.fastble.BleManager;
import com.clj.fastble.callback.BleScanCallback;
import com.clj.fastble.data.BleDevice;
import com.clj.fastble.scan.BleScanRuleConfig;
import com.example.cloudecg.Ecg;
import com.example.moreconnected.View.HeartView;
import com.example.moreconnected.View.ThermometerView;
import com.example.temperaturestick.Temperature;
import com.example.thebelt.TheBelt;
import com.example.theenvironment.Theenvironment;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.vmove.signalproc.SignalProc;

import java.text.BreakIterator;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements OnChartValueSelectedListener {
    //体温折线图
    private int Xmain=0;
    private LineChart chart;
    private String Name="";
    private String deviceAddress="";
    private SignalProc mSignalProc = new SignalProc();
    //云心电1
    private TextView cloud_ECG_data_one;//数据
    private HeartView waveline_one;
    private LinearLayout Cloud_posts_one;
    //云心电2
    private TextView cloud_ECG_data_two;//数据
    private HeartView waveline_two;
    private LinearLayout Cloud_posts_two;
    //云心电3
    private TextView cloud_ECG_data_three;//数据
    private HeartView waveline_threeo;
    private LinearLayout Cloud_posts_three;

    private boolean Temperature_judgment_bb = false;
    private boolean Temperature_judgment_c = false;

    private TextView name_a1, name_a2, name_a3;//名字
    private Button  bluetooth_state_one1,bluetooth_state_one2,bluetooth_state_one3;

    private TextView bluetooth_a, bluetooth_b, bluetooth_c;
    private LinearLayout The_whole;//整布局
    private TextView body_temperature_one;//体温1
    private RelativeLayout ody_temperature,dy_temperature;//体温
    private ThermometerView thermometerTv;

    //体温2
    private TextView body_temperature_two;
    //体温3
    private TextView body_temperature_three;

    //腰带1
    private LinearLayout the_belt_one;//腰带1
    private TextView actual_temperature_a, actual_temperature_b, actual_temperature_c, heart_rate, humidity;//腰带1
    //腰带2
    private LinearLayout the_belt_two;//腰带2
    private TextView actual_temperature_a_two, actual_temperature_b_two, actual_temperature_c_two, heart_rate_two, humidity_two;//腰带2
    private LinearLayout the_belt_three;//腰带3
    private TextView actual_temperature_a_three, actual_temperature_b_three, actual_temperature_c_three, heart_rate_three, humidity_three;//腰带3
    //环境1
    private TextView temperature_value;//实时温度
    private TextView humidity1;//实时湿度
    private TextView temperature;//湿球温度
    private TextView number;//热指数
    private TextView index;//WBGT指数
    private TextView point;//露点
    private TextView light_intensity;//强光
    private TextView wind_speed;//风速
    private TextView electricity;//电量
    private LinearLayout The_environment_one;
    //环境2
    private TextView temperature_value_two;//实时温度
    private TextView humidity1_two;//实时湿度
    private TextView temperature_two;//湿球温度
    private TextView number_two;//热指数
    private TextView index_two;//WBGT指数
    private TextView point_two;//露点
    private TextView light_intensity_two;//强光
    private TextView wind_speed_two;//风速
    private TextView electricity_two;//电量
    private LinearLayout The_environment_two;
    //环境3
    private TextView temperature_value_three;//实时温度
    private TextView humidity1_three;//实时湿度
    private TextView temperature_three;//湿球温度
    private TextView number_three;//热指数
    private TextView index_three;//WBGT指数
    private TextView point_three;//露点
    private TextView light_intensity_three;//强光
    private TextView wind_speed_three;//风速
    private TextView electricity_three;//电量
    private LinearLayout The_environment_three;


    private CheckBox CheckBox1, CheckBox2, CheckBox3;
    private CustomPopWindow mCustomPopWindow;
    private TextView bluetooth_address_one, bluetooth_address_two, bluetooth_address_three;
    private TextView universal;
    private ListView bluetooth_data;//列表
    private List<RefreshListItem> data1 = new LinkedList<>();
    private RelativeLayout at_the_bottom_of_the_bureau;//选择要连接的3个设备
    private Button at_the_bottom_of_the_bureau_one;
    private Button the_connection_one;//连接
    private RefreshListItem item;
    private RefreshListAdapter mAdapter;
    private int conditions = 0;
    private String mValue1;
    private String Mac1 = "1", Mac2 = "2", Mac3 = "3";
    private String name1="4", name2="5", name3="6";
    private ImageView mark_one;
    private int value1, value2, value3, value4, value5, value6, value7, value8, value9;
    private int value11, value21, value31, value41, value51, value61, value71, value81, value91;
    private String path;
    private String currenttime,currenttime3,currenttime2;
    private Handler bleHandler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            DecimalFormat df = new DecimalFormat("0.00");//格式化小数
            switch (msg.what) {
                //搜索并连接
                case 1:
                    mValue1 = String.valueOf(msg.obj);
                    break;
                case 2:
                    byte[] data = (byte[]) msg.obj;
                    value1 = getShort(data[0], data[1]);
                    value2 = getShort(data[2], data[3]);

                    String num = df.format((float) value1 / 100);//返回的是String类型
                    String numV = df.format((float) value2 / 100);//返回的是String类型
                  if (deviceAddress==Mac1){
                      Date date = new Date();
                      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/ HH:mm:ss,");
                      String temporary = dateFormat.format(date);
                      path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime +name1+Mac1+ "体温.txt";
                      TXTManager.write(path,temporary+num+"\n");
                      path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime +name1+ "体温.txt";
                      TXTManager.write(path,num+"\n");
                      thermometerTv.setValueAndStartAnim((float)value1 / 100);
                      body_temperature_one.setText(  num + "℃" );
                  }
                 if (deviceAddress==Mac2){
                     Date date = new Date();
                     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/ HH:mm:ss,");
                     String temporary = dateFormat.format(date);
                     path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime2 +name2+Mac2+ "体温.txt";
                     TXTManager.write(path,temporary+num+"\n");
                     path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime2 +name2+ "体温.txt";
                     TXTManager.write(path,num+"\n");
                     addEntry((float)value1 / 100);
                     Log.d("Yzhi",(float)value1 / 100+"lai"+value1);
                     body_temperature_two.setText("体温:" + num + "℃" + "电压:" + numV + "V");
                }
                    if (deviceAddress==Mac3){
                        Date date = new Date();
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/ HH:mm:ss,");
                        String temporary = dateFormat.format(date);
                        path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime3 +name3+Mac2+ "体温.txt";
                        TXTManager.write(path,temporary+num+"\n");
                        path = MainActivity.this.getExternalFilesDir("Download") + "/" + currenttime3 +name3+ "体温.txt";
                        TXTManager.write(path,num+"\n");
                        body_temperature_three.setText("体温:" + num + "℃" + "电压:" + numV + "V");
                    }

                    break;
                case 3:
                    byte[] data1 = (byte[]) msg.obj;
//                    Log.d("aqqa", ByteUtils.toHexString(data1));
//                    Addthedata(ByteUtils.toHexString(data));
                    if (data1[0] == -24) {
                        switch (data1[16]) {
                            //心率
                            case -96:
                                value4 = getShort(data1[18], data1[17]);
                                heart_rate.setText(value4 + "");
                                heart_rate_two.setText(value4 + "");
                                heart_rate_three.setText(value4 + "");
                                break;
                            //呼吸
                            case -80:
                                value5 = getShort(data1[18], data1[17]);

                                humidity.setText(value5 + "");
                                humidity_two.setText(value5 + "");
                                humidity_three.setText(value5 + "");

                                break;
                            //A
                            case -64:
                                value6 = getShort(data1[18], data1[17]);

                                actual_temperature_a.setText(df.format((float) value6 / 10));
                                actual_temperature_a_two.setText(df.format((float) value6 / 10));
                                actual_temperature_a_three.setText(df.format((float) value6 / 10));

                                break;
                            //b
                            case -63:
                                value7 = getShort(data1[18], data1[17]);

                                actual_temperature_b.setText(df.format((float) value7 / 10));
                                actual_temperature_b_two.setText(df.format((float) value7 / 10));
                                actual_temperature_b_three.setText(df.format((float) value7 / 10));

                                break;
                            //c
                            case -62:
                                value8 = getShort(data1[18], data1[17]);

                                actual_temperature_c_two.setText(df.format((float) value8 / 10));
                                actual_temperature_c.setText(df.format((float) value8 / 10));
                                actual_temperature_c_three.setText(df.format((float) value8 / 10));

                                break;
                        }
                    }
                    break;
                case 4:
                    byte[] data3 = (byte[]) msg.obj;
                    Log.d("aa", data3.toString());
                    value11 = getShort(data3[0], data3[1]);
                    value21 = getShort(data3[2], data3[3]);
                    value31 = getShort(data3[4], data3[5]);
                    value41 = getShort(data3[6], data3[7]);
                    value51 = getShort(data3[8], data3[9]);
                    value61 = getShort(data3[10], data3[11]);
                    value71 = getShort(data3[12], data3[3]);
                    value81 = getShort(data3[14], data3[15]);
                    DecimalFormat df2 = new DecimalFormat("0.00");//格式化小数
//1
                    temperature_value.setText((df2.format((float) value11 / 10)) + "℃");
                    humidity1.setText((df2.format((float) value21 / 10)) + "%RH");
                    temperature.setText((df2.format((float) value31 / 10)) + "℃");
                    index.setText((df2.format((float) value41 / 10)) + "℃");
                    number.setText((df2.format((float) value51 / 10)) + "℃");
                    point.setText((df2.format((float) value61 / 10)) + "℃");
                    light_intensity.setText(df2.format((float) value71 / 10));
                    wind_speed.setText((df2.format((float) value81 / 10)) + "0.1m/s");
                    electricity.setText((df2.format((float) value91 / 10)));
//2
                    temperature_value_two.setText((df2.format((float) value11 / 10)) + "℃");
                    humidity1_two.setText((df2.format((float) value21 / 10)) + "%RH");
                    temperature_two.setText((df2.format((float) value31 / 10)) + "℃");
                    index_two.setText((df2.format((float) value41 / 10)) + "℃");
                    number_two.setText((df2.format((float) value51 / 10)) + "℃");
                    point_two.setText((df2.format((float) value61 / 10)) + "℃");
                    light_intensity_two.setText(df2.format((float) value71 / 10));
                    wind_speed_two.setText((df2.format((float) value81 / 10)) + "0.1m/s");
                    electricity_two.setText((df2.format((float) value91 / 10)));
//3
                    temperature_value_three.setText((df2.format((float) value11 / 10)) + "℃");
                    humidity1_three.setText((df2.format((float) value21 / 10)) + "%RH");
                    temperature_three.setText((df2.format((float) value31 / 10)) + "℃");
                    index_three.setText((df2.format((float) value41 / 10)) + "℃");
                    number_three.setText((df2.format((float) value51 / 10)) + "℃");
                    point_three.setText((df2.format((float) value61 / 10)) + "℃");
                    light_intensity_three.setText(df2.format((float) value71 / 10));
                    wind_speed_three.setText((df2.format((float) value81 / 10)) + "0.1m/s");
                    electricity_three.setText((df2.format((float) value91 / 10)));
                    break;

                case 5:
                    byte[] data5 = (byte[]) msg.obj;
                    cloud_ECG_data_one.setText(DataTools.bytesToHexString(data5));
                    if (data5.length == 20) {
                        int[] b6 = new int[6];
                        int[] b8 = new int[3];
                        float[] b7 = new float[6];
                        int a = 0;
                        for (int i = 2; i < 20; i = i + 3) {
                            b6[a] = ((data5[i] & 0xFF) << 16) | ((data5[i + 1] & 0xFF) << 8) | ((data5[i + 2] & 0xFF));
                            a++;
                        }
                        for (int i = 0; i < b6.length; i = i + 2) {
                            int b0 = mSignalProc.Run(b6[i]);
                            int out = b0 * 5000 / 20971;
                            if ("BW-ECG-02".equals(name1)){
                                waveline_one.offer(out + 5000);
                            }
                            if ("BW-ECG-02".equals(name2)){
                                waveline_two.offer(out + 5000);
                            }
                            if ("BW-ECG-02".equals(name3)){
                                waveline_threeo.offer(out + 5000);
                            }
                            Log.d("shoujisa", out + "");
                        }
                    }
                    break;
                case 10:
                    int value = (int) msg.obj;
                    BluetoothStatusDetermination(value,Name);//蓝牙状态值显示
                    break;
                case 11:
                    int value1 = (int) msg.obj;
                    BluetoothStatusDetermination(value1,"FHYDCSH2");
                    break;
                case 12:
                    int value2 = (int) msg.obj;
                    BluetoothStatusDetermination(value2,"QZ_MC");
                    break;
                case 13:
                    int value3 = (int) msg.obj;
                    BluetoothStatusDetermination(value3,"BW-ECG-02");
                    break;
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mSignalProc.Init(100);
        find_the_id();//绑定数据
        BluetoothDataCallback();//蓝牙回调
        Temperature.sharedCenter().Initializethe(MainActivity.this);
    }
    private void BluetoothStatusDetermination(int i, String name) {
        if (name.equals(name1)) {
            switch (i) {
                case 1:
                    bluetooth_state_one1.setText("连接中...");
                    break;
                case 2:
                    bluetooth_state_one1.setText("已连接");
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
                    currenttime = dateFormat.format(date);
                    break;
                case 3:
                    bluetooth_state_one1.setText("未连接");
                    break;
            }
        }
        if (name.equals(name2)){
            switch (i) {
                case 1:
                    bluetooth_state_one2.setText("连接中...");
                    break;
                case 2:
                    bluetooth_state_one2.setText("已连接");
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
                    currenttime2 = dateFormat.format(date);
                    break;
                case 3:
                    bluetooth_state_one2.setText("未连接");
                    break;
            }

        }
        if (name.equals(name3)){
            switch (i) {
                case 1:
                    bluetooth_state_one3.setText("连接中...");
                    break;
                case 2:
                    bluetooth_state_one3.setText("已连接");
                    Date date = new Date();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
                    currenttime3 = dateFormat.format(date);
                    break;
                case 3:
                    bluetooth_state_one3.setText("未连接");
                    break;
            }

        }
    }

    private void BluetoothDataCallback() {
        notice();//通知
        state();//状态
        //搜索
        Temperature.sharedCenter().setscandata(new Temperature.Onscanning() {
            @Override
            public void number(String name, String Mac) {
                String S = "蓝牙名字" + name + "地址" + Mac;
                Log.d("搜到", S);
                Message message1 = new Message();
                message1.what = 1;
                message1.obj = S;
                bleHandler.sendMessage(message1);
                item = new RefreshListItem();
                item.ma = name;
                item.mb = Mac;
                data1.add(item);
                mAdapter.setData(data1, 1 == 1 ? true : false);
                bluetooth_data.setAdapter(mAdapter);
                mAdapter.notifyDataSetChanged();
            }
        });


    }
//状态回调
    private void state() {
        //体温连接状态
        Temperature.sharedCenter().setReceivedCallback(new Temperature.OnConnectionstatus() {
            @Override
            public void state(boolean mTheconnected, boolean mIntheconnection,String  Namev) {
                Name=Namev;
                int valuem1 = 0;
                if (mTheconnected) {
                    valuem1 = 1;
                }
                if (mIntheconnection) {
                    valuem1 = 2;
                } else {
                    valuem1 = 3;
                }
                Message message1 = new Message();
                message1.what = 10;
                message1.obj = valuem1;
                bleHandler.sendMessage(message1);
            }
        });
        //腰带连接状态
        TheBelt.sharedCenter().setReceivedCallback(new TheBelt.OnConnectionstatus() {
            @Override
            public void state(boolean mTheconnected, boolean mIntheconnection) {
                int valuem1 = 0;
                if (mTheconnected) {
                    valuem1 = 1;
                }
                if (mIntheconnection) {
                    valuem1 = 2;
                } else {
                    valuem1 = 3;
                }
                Message message1 = new Message();
                message1.what = 11;
                message1.obj = valuem1;
                bleHandler.sendMessage(message1);
            }
        });
        //环境连接状态
        Theenvironment.sharedCenter().setReceivedCallback(new Theenvironment.OnConnectionstatus() {
            @Override
            public void state(boolean mTheconnected, boolean mIntheconnection) {
                int valuem1 = 0;
                if (mTheconnected) {
                    valuem1 = 1;
                }
                if (mIntheconnection) {
                    valuem1 = 2;
                } else {
                    valuem1 = 3;
                }
                Message message1 = new Message();
                message1.what = 12;
                message1.obj = valuem1;
                bleHandler.sendMessage(message1);
            }
        });
        //云心贴连接状态
        Ecg.sharedCenter().setReceivedCallback(new Ecg.OnConnectionstatus() {
            @Override
            public void state(boolean mTheconnected, boolean mIntheconnection) {
                int valuem1 = 0;
                if (mTheconnected) {
                    valuem1 = 1;
                }
                if (mIntheconnection) {
                    valuem1 = 2;
                } else {
                    valuem1 = 3;
                }
                Message message1 = new Message();
                message1.what = 13;
                message1.obj = valuem1;
                bleHandler.sendMessage(message1);
            }
        });
    }

    //通知
    private void notice() {
        //体温 通知
        Temperature.sharedCenter().setReceivedata(new Temperature.OnReceivedata() {
            @Override
            public void data(byte[] data ,String deviceAddresss) {
                deviceAddress=deviceAddresss;
                Message message1 = new Message();
                message1.what = 2;
                message1.obj = data;
                bleHandler.sendMessage(message1);
            }
        });
        //腰带 通知
        TheBelt.sharedCenter().setReceivedata(new TheBelt.OnReceivedata() {
            @Override
            public void data(byte[] data) {
                if (data.length == 20) {
                    Message message1 = new Message();
                    message1.what = 3;
                    message1.obj = data;
                    bleHandler.sendMessage(message1);
                }
            }
        });
        //环境 通知
        Theenvironment.sharedCenter().setReceivedata(new Theenvironment.OnReceivedata() {
            @Override
            public void data(byte[] data) {
                Message message1 = new Message();
                message1.what = 4;
                message1.obj = data;
                bleHandler.sendMessage(message1);
            }
        });
        //云心贴 通知
        Ecg.sharedCenter().setReceivedata(new Ecg.OnReceivedata() {
            @Override
            public void data(byte[] data) {
                Message message1 = new Message();
                message1.what = 5;
                message1.obj = data;
                bleHandler.sendMessage(message1);
            }
        });
    }

    //找到id
    private void find_the_id() {
        ody_temperature=findViewById(R.id.ody_temperature);
        dy_temperature=findViewById(R.id.dy_temperature);
//        体温 折线
        chart = findViewById(R.id.chart1);
        chart.setOnChartValueSelectedListener(this);
        chart.setDrawGridBackground(false);
        chart.getDescription().setEnabled(false);
        chart.setNoDataText("数据加载中");
        chart.invalidate();
        //云心贴1
        Cloud_posts_two=findViewById(R.id.Cloud_posts_two);
        Cloud_posts_three=findViewById(R.id.Cloud_posts_three);
        Cloud_posts_one=findViewById(R.id.Cloud_posts_one);
        waveline_one = findViewById(R.id.waveline_one);
        waveline_two= findViewById(R.id.waveline_one_two);
        waveline_threeo= findViewById(R.id.waveline_one_three);
        cloud_ECG_data_one = findViewById(R.id.cloud_ECG_data_one);
        name_a1 = findViewById(R.id.name_a1);
        bluetooth_state_one1 = findViewById(R.id.bluetooth_state_one1);
        bluetooth_state_one2 = findViewById(R.id.bluetooth_state_one2);
        bluetooth_state_one3 = findViewById(R.id.bluetooth_state_one3);
        name_a2 = findViewById(R.id.name_a2);
        name_a3 = findViewById(R.id.name_a3);
        thermometerTv=findViewById(R.id.tv_thermometer);
        //体温2
        body_temperature_two = findViewById(R.id.body_temperature_two);
        //体温3
        body_temperature_three = findViewById(R.id.body_temperature_three);
        //蓝牙状态
        bluetooth_a = findViewById(R.id.bluetooth_a);
        bluetooth_b = findViewById(R.id.bluetooth_b);
        bluetooth_c = findViewById(R.id.bluetooth_c);
        //环境3
        The_environment_three = findViewById(R.id.The_environment_three);
        temperature_value_three = findViewById(R.id.temperature_value_three);
        humidity1_three = findViewById(R.id.humidity1_three);
        temperature_three = findViewById(R.id.temperature_three);
        point_three = findViewById(R.id.point_three);
        number_three = findViewById(R.id.number_three);
        index_three = findViewById(R.id.index_three);
        light_intensity_three = findViewById(R.id.light_intensity_three);
        wind_speed_three = findViewById(R.id.wind_speed_three);
        electricity_three = findViewById(R.id.electricity_three);
        //环境2
        The_environment_two = findViewById(R.id.The_environment_two);
        temperature_value_two = findViewById(R.id.temperature_value_two);
        humidity1_two = findViewById(R.id.humidity1_two);
        temperature_two = findViewById(R.id.temperature_two);
        point_two = findViewById(R.id.point_two);
        number_two = findViewById(R.id.number_two);
        index_two = findViewById(R.id.index_two);
        light_intensity_two = findViewById(R.id.light_intensity_two);
        wind_speed_two = findViewById(R.id.wind_speed_two);
        electricity_two = findViewById(R.id.electricity_two);
        //环境1
        The_environment_one = findViewById(R.id.The_environment_one);
        temperature_value = findViewById(R.id.temperature_value);
        humidity1 = findViewById(R.id.humidity1);
        temperature = findViewById(R.id.temperature);
        point = findViewById(R.id.point);
        number = findViewById(R.id.number);
        index = findViewById(R.id.index);
        light_intensity = findViewById(R.id.light_intensity);
        wind_speed = findViewById(R.id.wind_speed);
        electricity = findViewById(R.id.electricity);
        //腰带1
        the_belt_one = findViewById(R.id.the_belt_one);
        heart_rate = findViewById(R.id.heart_rate);
        humidity = findViewById(R.id.humidity);
        actual_temperature_a = findViewById(R.id.actual_temperature_a);
        actual_temperature_b = findViewById(R.id.actual_temperature_b);
        actual_temperature_c = findViewById(R.id.actual_temperature_c);
        //腰带2
        the_belt_two = findViewById(R.id.the_belt_two);
        heart_rate_two = findViewById(R.id.heart_rate_two);
        humidity_two = findViewById(R.id.humidity_two);
        actual_temperature_a_two = findViewById(R.id.actual_temperature_a_two);
        actual_temperature_b_two = findViewById(R.id.actual_temperature_b_two);
        actual_temperature_c_two = findViewById(R.id.actual_temperature_c_two);
        //腰带3
        the_belt_three = findViewById(R.id.the_belt_three);
        heart_rate_three = findViewById(R.id.heart_rate_three);
        humidity_three = findViewById(R.id.humidity_three);
        actual_temperature_a_three = findViewById(R.id.actual_temperature_a_three);
        actual_temperature_b_three = findViewById(R.id.actual_temperature_b_three);
        actual_temperature_c_three = findViewById(R.id.actual_temperature_c_three);
        CheckBox1 = findViewById(R.id.checkBox1);
        CheckBox2 = findViewById(R.id.checkBox2);
        CheckBox3 = findViewById(R.id.checkBox3);
        body_temperature_one = findViewById(R.id.body_temperature_one);
        at_the_bottom_of_the_bureau_one = findViewById(R.id.at_the_bottom_of_the_bureau_one);
        bluetooth_data = findViewById(R.id.bluetooth_data);
        bluetooth_address_one = findViewById(R.id.bluetooth_address_one);
        bluetooth_address_two = findViewById(R.id.bluetooth_address_two);
        bluetooth_address_three = findViewById(R.id.bluetooth_address_three);
        at_the_bottom_of_the_bureau = findViewById(R.id.at_the_bottom_of_the_bureau);
        mAdapter = new RefreshListAdapter(this);
        bluetooth_data.setAdapter(mAdapter);
        The_whole = findViewById(R.id.The_whole);
        waveline_one.setHz(100);
        waveline_two.setHz(100);
        waveline_threeo.setHz(100);
    }
    public void monClick(View view) {
        switch (view.getId()) {

            //重连1
            case R.id.bluetooth_state_one1:
                boolean statusd = name3.contains("BWTP010");
                if (statusd){
                    Temperature.sharedCenter().Macconnection(Mac1);
                }
                switch (name1) {
//                    case "BWTP010oc":
//                        Temperature.sharedCenter().Macconnection(Mac1);
//                        break;
//                    case "BWTP010oC":
//                        Temperature.sharedCenter().Macconnection(Mac1);
//                        break;
//                    case "BWTP010oN":
//                        Temperature.sharedCenter().Macconnection(Mac1);
//                        break;
                    case "FHYDCSH2":
                        TheBelt.sharedCenter().Macconnection(Mac1);
                        break;
                    case "QZ_MC":
                        Theenvironment.sharedCenter().Macconnection(Mac1);
                        break;
                    case "BW-ECG-02":
                        Ecg.sharedCenter().Macconnection(Mac1);
                        break;
                }
                break;
            //重连2
            case R.id.bluetooth_state_one2:
                boolean statusa = name3.contains("BWTP010");
                if (statusa){
                    Temperature.sharedCenter().Macconnection(Mac2);
                }
                switch (name2) {
//                    case "BWTP010oc":
//                        Temperature.sharedCenter().Macconnection(Mac2);
//                        break;
//                    case "BWTP010oC":
//                        Temperature.sharedCenter().Macconnection(Mac2);
//                        break;
//                    case "BWTP010oN":
//                        Temperature.sharedCenter().Macconnection(Mac2);
//                        break;
                    case "FHYDCSH2":
                        TheBelt.sharedCenter().Macconnection(Mac2);
                        break;
                    case "QZ_MC":
                        Theenvironment.sharedCenter().Macconnection(Mac2);
                        break;
                    case "BW-ECG-02":
                        Ecg.sharedCenter().Macconnection(Mac1);
                        break;
                }
                break;
            //重连3
            case R.id.bluetooth_state_one3:
                boolean statusb = name3.contains("BWTP010");
                if (statusb){
                    Temperature.sharedCenter().Macconnection(Mac3);
                }
                switch (name3) {
//                    case "BWTP010oc":
//                        Temperature.sharedCenter().Macconnection(Mac3);
//                        break;
//                    case "BWTP010oC":
//                        Temperature.sharedCenter().Macconnection(Mac3);
//                        break;
//                    case "BWTP010oN":
//                        Temperature.sharedCenter().Macconnection(Mac3);
//                        break;
                    case "FHYDCSH2":
                        TheBelt.sharedCenter().Macconnection(Mac3);
                        break;
                    case "QZ_MC":
                        Theenvironment.sharedCenter().Macconnection(Mac3);
                        break;
                    case "BW-ECG-02":
                        Ecg.sharedCenter().Macconnection(Mac3);
                        break;
                }
                break;
            //绑定用户3
            case R.id.binding_three:
                Ecg.sharedCenter().Writecommand("e841aa0400320032000000000000000000212c37");//填写用户id e841+18个字节
                break;
            //设备号3
            case R.id.equipment_three:
                Ecg.sharedCenter().WritecommandEquipment();
                break;
            //单机采集3
            case R.id.collect_three:
                Ecg.sharedCenter().WritecommandCollecting();
                break;
            //结束采集3
            case R.id.Theendofthe_three:
                Ecg.sharedCenter().WritecommandAfter();
                break;
            //实时采集3
            case R.id.real_time_three:
                Ecg.sharedCenter().WritecommandReal();
                break;
            //停止实时采集3
            case R.id.stop_three:
                Ecg.sharedCenter().WritecommandRealAfter();
                break;
            //装订时间3
            case R.id.bindingtime_three:
                Ecg.sharedCenter().WritecommandTopLoading();
                break;
            //设备时间3
            case R.id.Equipment_time_three:
                Ecg.sharedCenter().WritecommandTime();
            //绑定用户2
            case R.id.binding_two:
                Ecg.sharedCenter().Writecommand("e841aa0400320032000000000000000000212c37");//填写用户id e841+18个字节
                break;
            //设备号2
            case R.id.equipment_two:
                Ecg.sharedCenter().WritecommandEquipment();
                break;
            //单机采集2
            case R.id.collect_two:
                Ecg.sharedCenter().WritecommandCollecting();
                break;
            //结束采集2
            case R.id.Theendofthe_two:
                Ecg.sharedCenter().WritecommandAfter();
                break;
            //实时采集2
            case R.id.real_time_two:
                Ecg.sharedCenter().WritecommandReal();
                break;
            //停止实时采集2
            case R.id.stop_two:
                Ecg.sharedCenter().WritecommandRealAfter();
                break;
            //装订时间2
            case R.id.bindingtime_two:
                Ecg.sharedCenter().WritecommandTopLoading();
                break;
            //设备时间2
            case R.id.Equipment_time_two:
                Ecg.sharedCenter().WritecommandTime();
                //绑定用户
            case R.id.binding:
                Ecg.sharedCenter().Writecommand("e841aa0400320032000000000000000000212c37");//填写用户id e841+18个字节
                break;
            //设备号
            case R.id.equipment:
                Ecg.sharedCenter().WritecommandEquipment();
                break;
            //单机采集
            case R.id.collect:
                Ecg.sharedCenter().WritecommandCollecting();
                break;
            //结束采集
            case R.id.Theendofthe:
                Ecg.sharedCenter().WritecommandAfter();
                break;
            //实时采集
            case R.id.real_time:
                Ecg.sharedCenter().WritecommandReal();
                break;
            //停止实时采集
            case R.id.stop:
                Ecg.sharedCenter().WritecommandRealAfter();
                break;
            //装订时间
            case R.id.bindingtime:
                Ecg.sharedCenter().WritecommandTopLoading();
                break;
            //设备时间
            case R.id.Equipment_time:
                Ecg.sharedCenter().WritecommandTime();
                break;
//          重新加载
            case R.id.again:
                data1.clear();
                Temperature.sharedCenter().search();
                break;
            //   选择设备一
            case R.id.checkBox1:
                CheckBox2.setChecked(false);
                CheckBox3.setChecked(false);
                break;
            //  选择设备二
            case R.id.checkBox2:
                CheckBox1.setChecked(false);
                CheckBox3.setChecked(false);
                break;
            // 选择设备三
            case R.id.checkBox3:
                CheckBox2.setChecked(false);
                CheckBox1.setChecked(false);
                break;
            // 配置
            case R.id.at_the_bottom_of_the_bureau_one:
                data1.clear();
                Temperature.sharedCenter().DisconnectThe();
                The_whole.setVisibility(View.GONE);
                at_the_bottom_of_the_bureau.setVisibility(View.VISIBLE);
                at_the_bottom_of_the_bureau_one.setVisibility(View.GONE);
                Temperature.sharedCenter().search();
                break;
            // 连接
            case R.id.the_connection_one:
                if (Mac1 == "1" & Mac2 == "2" & Mac3 == "3") {
                    Toast.makeText(this, "请选择连接设备", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (Mac1.equals(Mac2) || Mac1.equals(Mac3) || Mac2.equals(Mac3)) {
                    Toast.makeText(this, "您选择了两个相同的设备", Toast.LENGTH_SHORT).show();
                } else {
                    The_whole.setVisibility(View.VISIBLE);
                    at_the_bottom_of_the_bureau.setVisibility(View.GONE);
                    if (Mac1 != "1") {
                        boolean statusccc = name1.contains("BWTP010");
                        if (statusccc){
                            name_a1.setText("体温贴"+name1+"地址:" + Mac1);
                            body_temperature_one.setVisibility(View.VISIBLE);
                            ody_temperature.setVisibility(View.VISIBLE);
                            Cloud_posts_one.setVisibility(View.GONE);//云新帖
                            the_belt_one.setVisibility(View.GONE);//腰带
                            Temperature.sharedCenter().Macconnection(Mac1);
                            at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                        }
                        switch (name1) {
//                            case "BWTP010oc"://临时加1
//                                name_a1.setText("体温贴BWTP010oc地址:" + Mac1);
//                                body_temperature_one.setVisibility(View.VISIBLE);
//                                ody_temperature.setVisibility(View.VISIBLE);
//                                Cloud_posts_one.setVisibility(View.GONE);//云新帖
//                                the_belt_one.setVisibility(View.GONE);//腰带
//                                Temperature.sharedCenter().Macconnection(Mac1);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oC"://临时加2
//                                name_a1.setText("体温贴BWTP010oC地址:" + Mac1);
//                                body_temperature_one.setVisibility(View.VISIBLE);
//                                ody_temperature.setVisibility(View.VISIBLE);
//                                Cloud_posts_one.setVisibility(View.GONE);//云新帖
//                                the_belt_one.setVisibility(View.GONE);//腰带
//                                Temperature.sharedCenter().Macconnection(Mac1);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oN":
//                                name_a1.setText("体温贴BWTP010oN地址:" + Mac1);
//                                body_temperature_one.setVisibility(View.VISIBLE);
//                                ody_temperature.setVisibility(View.VISIBLE);
//                                Cloud_posts_one.setVisibility(View.GONE);//云新帖
//                                the_belt_one.setVisibility(View.GONE);//腰带
//                                Temperature.sharedCenter().Macconnection(Mac1);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
                            case "FHYDCSH2":
                                name_a1.setText("腰带FHYDCSH2地址:" + Mac1);
                                the_belt_one.setVisibility(View.VISIBLE);//腰带
                                body_temperature_one.setVisibility(View.GONE);//体温
                                ody_temperature.setVisibility(View.GONE);
                                Cloud_posts_one.setVisibility(View.GONE);//云新帖
                                TheBelt.sharedCenter().Macconnection(Mac1);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "QZ_MC":
                                name_a1.setText("环境QZ_MC地址:" + Mac1);
                                The_environment_one.setVisibility(View.VISIBLE);//环境
                                the_belt_one.setVisibility(View.GONE);//腰带
                                body_temperature_one.setVisibility(View.GONE);//体温
                                ody_temperature.setVisibility(View.GONE);
                                Cloud_posts_one.setVisibility(View.GONE);//云新帖
                                Theenvironment.sharedCenter().Macconnection(Mac1);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "BW-ECG-02":
                                name_a1.setText("云心贴BW-ECG-02地址:" + Mac1);
                                Cloud_posts_one.setVisibility(View.VISIBLE);//云新帖
                                The_environment_one.setVisibility(View.GONE);//环境
                                the_belt_one.setVisibility(View.GONE);//腰带
                                body_temperature_one.setVisibility(View.GONE);//体温
                                ody_temperature.setVisibility(View.GONE);
                                Ecg.sharedCenter().Macconnection(Mac1);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                        }
                    }
                    if (Mac2 != "2") {
                        boolean statuscc = name2.contains("BWTP010");
                        if (statuscc){
                            name_a2.setText("体温贴"+name2+"地址:" + Mac2);
                            the_belt_two.setVisibility(View.GONE);//腰带
                            body_temperature_two.setVisibility(View.GONE);
                            dy_temperature.setVisibility(View.VISIBLE);
                            Temperature.sharedCenter().Macconnection(Mac2);
                            at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                        }
                        switch (name2) {
//                            case "BWTP010oc"://临时加
//                                name_a2.setText("体温贴BWTP010oc地址:" + Mac2);
//                                the_belt_two.setVisibility(View.GONE);//腰带
//                                body_temperature_two.setVisibility(View.GONE);
//                                dy_temperature.setVisibility(View.VISIBLE);
//                                Temperature.sharedCenter().Macconnection(Mac2);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oC"://临时加
//                                name_a2.setText("体温贴BWTP010oC地址:" + Mac2);
//                                dy_temperature.setVisibility(View.VISIBLE);
//                                the_belt_two.setVisibility(View.GONE);//腰带
//                                body_temperature_two.setVisibility(View.GONE);
//                                Temperature.sharedCenter().Macconnection(Mac2);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oN":
//                                name_a2.setText("体温贴BWTP010oN地址:" + Mac2);
//                                dy_temperature.setVisibility(View.VISIBLE);
//                                the_belt_two.setVisibility(View.GONE);//腰带
//                                body_temperature_two.setVisibility(View.GONE);
//                                Temperature.sharedCenter().Macconnection(Mac2);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
                            case "FHYDCSH2":
                                name_a2.setText("腰带FHYDCSH2地址:" + Mac2);
                                dy_temperature.setVisibility(View.GONE);
                                the_belt_two.setVisibility(View.VISIBLE);//腰带
                                The_environment_two.setVisibility(View.GONE);
                                body_temperature_two.setVisibility(View.GONE);
                                TheBelt.sharedCenter().Macconnection(Mac2);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "QZ_MC":
                                dy_temperature.setVisibility(View.GONE);
                                name_a2.setText("环境QZ_MC地址:" + Mac2);
                                the_belt_two.setVisibility(View.GONE);//腰带
                                The_environment_two.setVisibility(View.VISIBLE);
                                body_temperature_two.setVisibility(View.GONE);
                                Theenvironment.sharedCenter().Macconnection(Mac2);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "BW-ECG-02":
                                dy_temperature.setVisibility(View.GONE);
                                name_a2.setText("云心贴BW-ECG-02地址:" + Mac1);
                                Cloud_posts_two.setVisibility(View.VISIBLE);//云新帖
                                the_belt_two.setVisibility(View.GONE);//腰带
                                The_environment_two.setVisibility(View.GONE);
                                body_temperature_two.setVisibility(View.GONE);
                                Ecg.sharedCenter().Macconnection(Mac2);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                        }
                    }
                    if (Mac3 != "3") {
                        boolean statusc = name3.contains("BWTP010");
                        if ( statusc){
                            name_a3.setText("体温贴:"+name3 +"地址:"+ Mac3);
                            Cloud_posts_three.setVisibility(View.GONE);//云新帖
                            body_temperature_three.setVisibility(View.VISIBLE);
                            the_belt_three.setVisibility(View.GONE);//腰带
                            The_environment_three.setVisibility(View.GONE);
                            Temperature.sharedCenter().Macconnection(Mac3);
                            at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                        }
                        switch (name3) {
//                            case "BWTP010oC":
//                                name_a3.setText("体温贴BWTP010oC地址:" + Mac3);
//                                Cloud_posts_three.setVisibility(View.GONE);//云新帖
//                                body_temperature_three.setVisibility(View.VISIBLE);
//                                the_belt_three.setVisibility(View.GONE);//腰带
//                                The_environment_three.setVisibility(View.GONE);
//                                Temperature.sharedCenter().Macconnection(Mac3);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oc":
//                                name_a3.setText("体温贴BWTP010oc地址:" + Mac3);
//                                Cloud_posts_three.setVisibility(View.GONE);//云新帖
//                                body_temperature_three.setVisibility(View.VISIBLE);
//                                the_belt_three.setVisibility(View.GONE);//腰带
//                                The_environment_three.setVisibility(View.GONE);
//                                Temperature.sharedCenter().Macconnection(Mac3);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
//                            case "BWTP010oN":
//                                name_a3.setText("体温贴BWTP010oN地址:" + Mac3);
//                                Cloud_posts_three.setVisibility(View.GONE);//云新帖
//                                body_temperature_three.setVisibility(View.VISIBLE);
//                                the_belt_three.setVisibility(View.GONE);//腰带
//                                The_environment_three.setVisibility(View.GONE);
//                                Temperature.sharedCenter().Macconnection(Mac3);
//                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
//                                break;
                            case "FHYDCSH2":
                                name_a3.setText("腰带FHYDCSH2地址:" + Mac3);
                                Cloud_posts_three.setVisibility(View.GONE);//云新帖
                                body_temperature_three.setVisibility(View.GONE);
                                the_belt_three.setVisibility(View.VISIBLE);//腰带
                                The_environment_three.setVisibility(View.GONE);
                                TheBelt.sharedCenter().Macconnection(Mac3);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "QZ_MC":
                                name_a3.setText("环境QZ_MC地址:" + Mac3);
                                Cloud_posts_three.setVisibility(View.GONE);//云新帖
                                the_belt_three.setVisibility(View.GONE);//腰带
                                The_environment_three.setVisibility(View.VISIBLE);
                                body_temperature_three.setVisibility(View.GONE);
                                Theenvironment.sharedCenter().Macconnection(Mac3);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;
                            case "BW-ECG-02":
                                name_a3.setText("云心贴BW-ECG-02地址:" + Mac3);
                                Cloud_posts_three.setVisibility(View.VISIBLE);//云新帖
                                the_belt_three.setVisibility(View.GONE);//腰带
                                The_environment_three.setVisibility(View.GONE);
                                body_temperature_three.setVisibility(View.GONE);
                                Ecg.sharedCenter().Macconnection(Mac3);
                                at_the_bottom_of_the_bureau_one.setVisibility(View.VISIBLE);
                                break;

                        }
                    }
                }
                break;

        }
    }

    private void Addthedata(String data) {

        item = new RefreshListItem();
        item.ma = data;
        data1.add(item);
        mAdapter.setData(data1, 1 == 1 ? true : false);
        bluetooth_data.setAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();

    }

    private class RefreshListItem {
        public String ma;
        public String mb;
        public String mc;
    }

    //单条布局
    private class RefreshListAdapter extends BaseAdapter<RefreshListItem> {

        public RefreshListAdapter(Activity context) {
            super(context);
        }

        @Override
        protected int getItemLayoutId(int itemViewType) {
            return R.layout.data_lits;
        }

        @Override
        protected void handleItem(int itemViewType, int position, final RefreshListItem item, ViewHolder holder, boolean reused) {
            boolean status = item.ma.contains("BWTP010");
            if (status){
                holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.wendu));
                holder.get(R.id.monotonous_data, TextView.class).setText("体温贴" + item.ma + "地址:" + item.mb);
            }
            switch (item.ma) {


//
//                case "BWTP010oc":
//                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                    holder.get(R.id.monotonous_data, TextView.class).setText("体温贴" + item.ma + "地址:" + item.mb);
//                    break;
//                case "BWTP010oC":
//                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                    holder.get(R.id.monotonous_data, TextView.class).setText("体温贴" + item.ma + "地址:" + item.mb);
//                    break;
//                case "BWTP010oN":
//                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                    holder.get(R.id.monotonous_data, TextView.class).setText("体温贴" + item.ma + "地址:" + item.mb);
//                    break;
                case "FHYDCSH2":
                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.yaodai));
                    holder.get(R.id.monotonous_data, TextView.class).setText("腰带" + item.ma + "地址:" + item.mb);
                    break;
                case "QZ_MC":
                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.huanjing));
                    holder.get(R.id.monotonous_data, TextView.class).setText("环境" + item.ma + "地址:" + item.mb);
                    break;
                case "BW-ECG-02":
                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.xindian));
                    holder.get(R.id.monotonous_data, TextView.class).setText("云心贴" + item.ma + "地址:" + item.mb);
                    break;
                case "emyHealth":
                    holder.get(R.id.desmond, ImageView.class).setImageDrawable(getResources().getDrawable(R.drawable.xindiantie));
                    holder.get(R.id.monotonous_data, TextView.class).setText("综合心电" + item.ma + "地址:" + item.mb);
                    break;



            }
            holder.get(R.id.monotonous_data).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (CheckBox1.isChecked()) {
                        mark_one = findViewById(R.id.mark_one);
                        Mac1 = item.mb;
                        name1 = item.ma;
                        bluetooth_address_one = findViewById(R.id.bluetooth_address_one);
                        choose();
                    }
                    if (CheckBox2.isChecked()) {
                        Mac2 = item.mb;
                        name2 = item.ma;

                        mark_one = findViewById(R.id.mark_two);
                        bluetooth_address_one = findViewById(R.id.bluetooth_address_two);
                        choose();
                    }
                    if (CheckBox3.isChecked()) {
                        Mac3 = item.mb;
                        name3 = item.ma;
                        mark_one = findViewById(R.id.mark_three);
                        bluetooth_address_one = findViewById(R.id.bluetooth_address_three);
                        choose();
                    }

                }

                private void choose() {
                    boolean status = item.ma.contains("BWTP010");
                    if (status){
                        mark_one.setImageDrawable(getResources().getDrawable(R.drawable.wendu));
                        bluetooth_address_one.setText("体温贴" + item.ma + "地址:" + item.mb);
                    }
                    switch (item.ma) {
//                        case "BWTP010oc":
//                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                            bluetooth_address_one.setText("体温贴" + item.ma + "地址:" + item.mb);
//                            break;
//                        case "BWTP010oC":
//                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                            bluetooth_address_one.setText("体温贴" + item.ma + "地址:" + item.mb);
//                            break;
//                        case "BWTP010oN":
//                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.wendu));
//                            bluetooth_address_one.setText("体温贴" + item.ma + "地址:" + item.mb);
//                            break;
                        case "FHYDCSH2":
                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.yaodai));
                            bluetooth_address_one.setText("腰带" + item.ma + "地址:" + item.mb);
                            break;
                        case "QZ_MC":
                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.huanjing));
                            bluetooth_address_one.setText("环境" + item.ma + "地址:" + item.mb);
                            break;
                        case "BW-ECG-02":
                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.xindian));
                            bluetooth_address_one.setText("云心贴" + item.ma + "地址:" + item.mb);
                            break;
                        case "emyHealth":
                            mark_one.setImageDrawable(getResources().getDrawable(R.drawable.xindiantie));
                            bluetooth_address_one.setText("综合心电" + item.ma + "地址:" + item.mb);
                            break;
                    }

                }
            });

        }
    }

    public static short getShort(byte argB1, byte argB2) {
        return (short) ((argB1 & 0xFF) | (argB2 << 8));
    }

    public static float getV(int data) {
        float a = (float) (data - 8388608) * 4800f;
        float y = (float) (a / 16777215 / 6f) * 0.97f;
        Log.d("计算公式", "" + y);
        return y;
    }


    private void addEntry(float a) {


        LineData data = chart.getData();


        if (data == null) {
            data = new LineData();
            chart.setData(data);
        }

        ILineDataSet set = data.getDataSetByIndex(0);
        // set.addEntry(...); // can be called as well

        if (set == null) {
            set = createSet();
            data.addDataSet(set);
        }

        // choose a random dataSet
        int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
        ILineDataSet randomSet = data.getDataSetByIndex(randomDataSetIndex);
        float value = (float) (Math.random() * 50) + 50f * (randomDataSetIndex + 1);


        data.addEntry(new Entry(randomSet.getEntryCount(), a), randomDataSetIndex);
        data.notifyDataChanged();

        // let the chart know it's data has changed
        chart.notifyDataSetChanged();

        chart.setVisibleXRangeMaximum(6);
        //chart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
//
//            // this automatically refreshes the chart (calls invalidate())
        chart.moveViewTo(data.getEntryCount() - 7, 50f, YAxis.AxisDependency.LEFT);

    }




    private LineDataSet createSet() {

        LineDataSet set = new LineDataSet(null, "体温");
        set.setLineWidth(2.5f);
        set.setCircleRadius(4.5f);
        set.setColor(Color.rgb(240, 99, 99));
        set.setCircleColor(Color.rgb(240, 99, 99));
        set.setHighLightColor(Color.rgb(190, 190, 190));
        set.setAxisDependency(YAxis.AxisDependency.LEFT);
        set.setValueTextSize(10f);

        return set;
    }

    @Override
    public void onValueSelected(Entry e, Highlight h) {
        Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onNothingSelected() {}


}
